//
//  ViewController.m
//  LGNickLabel
//
//  Created by lg on 29/10/2019.
//  Copyright © 2019 lg. All rights reserved.
//

#import "ViewController.h"
#import <YYText/YYText.h>
#import "LGNickLabel.h"
#import <UIImageView+WebCache.h>

@interface ViewController ()<LGNickLabelDelegate>

@property(nonatomic) LGNickLabel *tempLabel;
@property(nonatomic) YYLabel *tempYYlabel;
@end

@implementation ViewController

- (IBAction)clickAction:(id)sender {
    self.tempLabel.images = @[@"https://picsum.photos/30",
                              @"https://picsum.photos/60",
                              @"https://picsum.photos/90"];
    
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"单行yylabel------"];
    text.yy_alignment = NSTextAlignmentCenter;
    self.tempYYlabel.attributedText = text;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setTitle:@"update" forState:UIControlStateNormal];
        [btn sizeToFit];
        [btn setCenter:CGPointMake(UIScreen.mainScreen.bounds.size.width/2, 100)];
        [btn addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    
    {
        YYLabel *yylabel = [[YYLabel alloc] initWithFrame:CGRectMake(0, 200, UIScreen.mainScreen.bounds.size.width, 50)];
        //MARK:打开异步显示，设置文本的时候会看到闪烁
        yylabel.displaysAsynchronously = YES;
        yylabel.backgroundColor = [UIColor greenColor];
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"单行yylabel------"];
        text.yy_alignment = NSTextAlignmentCenter;
        yylabel.attributedText = text;
        
        self.tempYYlabel = yylabel;
        [self.view addSubview:yylabel];
    }
    
    {
        LGNickLabel *oneLineLabel = [[LGNickLabel alloc] initWithFrame:CGRectMake(0, 400, UIScreen.mainScreen.bounds.size.width, 50)];
        oneLineLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
        oneLineLabel.backgroundColor = [UIColor greenColor];
        oneLineLabel.text = @"单行label------";
        oneLineLabel.images = @[@"https://picsum.photos/30",
                                @"https://picsum.photos/60",
                                @"https://picsum.photos/90"];
        oneLineLabel.imageViewSize = CGSizeMake(30, 30);
        oneLineLabel.space = 30;
        oneLineLabel.imageViewSpace = 20;
        oneLineLabel.textAlignment = NSTextAlignmentCenter;
        [oneLineLabel setConfigImageBlock:^(UIImageView * _Nonnull imageView, NSInteger index, NSString * _Nonnull imageUrlOrName) {
            [imageView sd_setImageWithURL:[NSURL URLWithString:imageUrlOrName]];
        }];
        
        
        oneLineLabel.delegate = self;
        
        self.tempLabel = oneLineLabel;
        [self.view addSubview:oneLineLabel];
    }
    
    {
        LGNickLabel *oneLineLabel = [[LGNickLabel alloc] initWithFrame:CGRectMake(0, 500, UIScreen.mainScreen.bounds.size.width, 50)];
        oneLineLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
        oneLineLabel.backgroundColor = [UIColor greenColor];
        oneLineLabel.text = @"单行label-----------航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊";
        oneLineLabel.images = @[@"img1",@"img2",@"arrow"];
        oneLineLabel.space = 10;
        [self.view addSubview:oneLineLabel];
        oneLineLabel.delegate = self;
    }
    
    {
        LGNickLabel *multiLineLabel = [[LGNickLabel alloc] initWithFrame:CGRectMake(0, 600, UIScreen.mainScreen.bounds.size.width, 100)];
        multiLineLabel.backgroundColor = [UIColor greenColor];
        multiLineLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
        multiLineLabel.text = @"多行label-----------航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊jflajjfajejf哈哈阿航啊";
        multiLineLabel.images = @[@"https://picsum.photos/40",
                                  @"https://picsum.photos/20",
                                  @"https://picsum.photos/16"];
        multiLineLabel.numberOfLines = 2;
    multiLineLabel.space = 10;
    multiLineLabel.imageViewSpace = 10;
        [multiLineLabel setConfigImageBlock:^(UIImageView * _Nonnull imageView, NSInteger index, NSString * _Nonnull imageUrlOrName) {
            [imageView sd_setImageWithURL:[NSURL URLWithString:imageUrlOrName]];
        }];
        [self.view addSubview:multiLineLabel];
        multiLineLabel.delegate = self;
    }
}

- (void)nickLabel:(LGNickLabel *)nickLabel didClickWithIndex:(NSInteger)index {
    NSLog(@"%s %ld", __func__, (long)index);
}

@end
